class DpdConsumer
  require 'rubygems'
  require 'open-uri'
  require 'rexml/document'
 
  
  def initialize(dpd_host, sdt, user, project, timestamp, password)
    @dpd_host = dpd_host
    @sdt = sdt
    @user = user
    @project = project
    @timestamp = timestamp
    @password = password
  end
  
  def get_representation
    response = nil
    url = @dpd_host + '/' + @sdt + '/' + @user + '/' + @project + '/' + @timestamp
    puts url
      Timeout::timeout(1000){
        response = open(url, :http_basic_authentication => [@user, @password])
     }
    xml = response.read
    document = REXML::Document.new(xml)
    puts document 
    
    if(@sdt == 'build')
      return BuildDpd.new(document)
    elsif(@sdt == 'codeissue')
      return CodeIssueDpd.new(document)
    elsif(@sdt == 'unittest')
      return UnitTestDpd.new(document)
    elsif(@sdt == 'commit')
      return CommitDpd.new(document)
    end
  end
end